package org.foj.presenter {
import com.anywebcam.mock.Mockery;

import flash.events.Event;
import flash.events.EventDispatcher;

import mx.rpc.IResponder;

import org.flexunit.async.Async;
import org.foj.dto.Issue;
import org.foj.event.EventDispatcherFactory;
import org.foj.event.UIEvent;
import org.foj.model.CommentModel;
import org.foj.presenter.CommentsListPresenter;
import org.foj.view.CommentsView;
import org.hamcrest.*;

public class CommentsListPresenterTest {

  public var target:CommentsListPresenter;
  public var mockery:Mockery;

  public var view:CommentsView;
  public var model:CommentModel;

  public var dispatcher:EventDispatcher;

  public var mockResponder:IResponder;

  public function CommentsListPresenterTest() {
  }

  [Before(async, timeout=7000)]
  public function setUp():void {
    mockery = new Mockery();
    mockery.prepare(CommentsView);
    mockery.prepare(CommentModel);

    dispatcher = EventDispatcherFactory.getEventDispatcher();
    Async.proceedOnEvent(this, mockery, Event.COMPLETE, 5000);
  }

  [After]
  public function tearDown():void {

  }

  [Test(async, timeout=5000)]
  public function testSelectedIssueChangedNoIssue():void {
    var selectedIssue:Issue = new Issue();
    model = mockery.strict(CommentModel) as CommentModel;
    view = mockery.strict(CommentsView) as CommentsView;

    mockery.mock(view).method("addCommentButtonEnabled").withArgs(false);
    mockery.mock(view).method("editCommentButtonEnabled").withArgs(false);
    mockery.mock(view).method("deleteCommentButtonEnabled").withArgs(false);

    mockery.mock(model).method("getCommentsForIssueId").withArgs(0, IResponder).once;

    target = new CommentsListPresenter(view, model);

    var event:UIEvent = new UIEvent(UIEvent.SELECTED_ISSUE_CHANGED);
    event.data = selectedIssue;
    dispatcher.dispatchEvent(event);

    mockery.verify(model, view);
  }


}
}